﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="SF_INPUTV3.ascx.vb" Inherits="WebForm_ManageSalesForecast_SF_INPUTV3" %>
<%@ Register Src="~/WebForm/ManageSalesForecast/SearchOption.ascx" TagName="ProductHierarchyControl"
    TagPrefix="My" %>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/WebForm/ManageSalesForecast/SFService.asmx" />
        <asp:ServiceReference Path="~/WebForm/BLSService.asmx" />
    </Services>
</asp:ScriptManagerProxy>
<%--<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>--%>

<script type="text/javascript">
var StartColumn="G1";//預設起始欄位
function <%=Me.ClientID %>SF_FindProd()
{
    var sheet = $get('SF_Spreadsheet1');
    var txtFindProd = $get('<%=Search2.FindControl("txtFindProd").ClientID %>');
    var hf_FindProd = $get('<%=hf_FindProd.ClientID %>');
    var targetcell = sheet.ActiveCell.Row >= 5 && sheet.ActiveCell.Column <= 6 ? sheet.ActiveCell : sheet.Range('A'+sheet.ActiveSheet.Rows.Count);

    if (txtFindProd.value=='')
    {
        alert('Please enter Keyword!!');
        return;
    }
    
    if (hf_FindProd.value != txtFindProd.value)
    {
        hf_FindProd.value = txtFindProd.value;
    }

    var ssConstants = sheet.Constants;
    var r = sheet.Range('A5:F'+sheet.ActiveSheet.Rows.Count);

    var fndCell = r.Find(txtFindProd.value,targetcell,ssConstants.xlValues, ssConstants.xlPart, ssConstants.xlByRows);

    if (fndCell == null)
    {
        alert('No more matched Keyword!!');
    }
    else
    {
        fndCell.Select();
        fndCell.Activate();
    }
}

function openSpecWindow(sType)
{
    if (sType=='TransferPLV')
    {
        var url = '<%= ResolveUrl("~/WebForm/ManageSalesForecast/TransferPLV_INPUT2.aspx") %>' + '?SessionID=<%=Me.SessionID %>&VControl=<%=Me.VControl %>' + '&PLVType=' + $get('<%=Search2.FindControl("ddlTransferPLV").ClientID %>').value;//[0].text
        window.open(url,'',OpenInCenter(600,500) + ',titlebar=0,resizable,status=1');
    }
    else if (sType=='Percentage')
    {
        var url = '<%= ResolveUrl("~/WebForm/CustomerGroupPercentageQuery.aspx") %>' + '?SessionID=<%=Me.SessionID %>';
        window.open(url,'',OpenInCenter(400,350) + ',toolbar=0,titlebar=0,resizable,scrollbars=Yes,status=1');
    }
    else if (sType=='GrossSales')
    {
        var url = '<%= ResolveUrl("~/WebForm/ManageSalesGross.aspx") %>'+'?Meeting=Y&Division=<%=Me.Division %>' + '&SessionID=<%=Me.SessionID %>';
        var ReportMode = '<%= Me.Search2.ReportMode %>';
        if (ReportMode=='1') //1:Meeting
        {
            url=url+'&MeetingSummary=Y';
        }
        else
        {
            url=url+'&MeetingSummary=N';
        }
        window.open(url,'',OpenInCenter(800,600) + ',toolbar=0,titlebar=0,resizable,scrollbars=Yes,status=1');
    }
    else if (sType=='Act')
    {
        var url = '<%= ResolveUrl("~/WebForm/ManageSalesAct.aspx") %>'+'?Meeting=Y&Division=<%=Me.Division %>' + '&SessionID=<%=Me.SessionID %>';
        window.open(url,'',OpenInCenter(800,600) + ',toolbar=0,titlebar=0,resizable,scrollbars=Yes,status=1');
    }
}

function openWindow(sType)
{
    var sheet = $get('SF_Spreadsheet1');
    var LevelCell = sheet.Range('A'+sheet.ActiveCell.Row);
    var MMPPCell = sheet.Range('C'+sheet.ActiveCell.Row);
    var TypeCell = sheet.Range('E'+sheet.ActiveCell.Row);
    var YearCell = sheet.cells(TypeCell.row,TypeCell.column+1);
    var SapCodeCell;
    
    if(TypeCell.value == 'TTL')
    {
        SapCodeCell = sheet.Range('B'+(sheet.ActiveCell.Row-2));
    }
    else
    {
        SapCodeCell = sheet.Range('B'+sheet.ActiveCell.Row);
    }
        
    if ((TypeCell.value == 'S' || TypeCell.value == 'P' || (TypeCell.value == 'TTL' && YearCell.value == 'Y')) && LevelCell.value == 'SKU')
    {
        if (sType=='ChannelSpectrum')
        {
            var url = '<%= ResolveUrl("~/Webform/ManageSalesForecast/ChannelSpectrumV2.aspx") %>'; 
        }
        else if (sType=='ProductSpectrum')
        {
            if(MMPPCell.value == '01' || MMPPCell.value == '02' || MMPPCell.value == '03' || MMPPCell.value == '04' || MMPPCell.value == '05' || MMPPCell.value == '06')
            {
                var url = '<%= ResolveUrl("~/Webform/ManageSalesForecast/ProductSpectrumV2.aspx") %>';
            }
            else
            {
                alert("The SKUs belong to 07~09, and therefore can't use product spectrum!!");
                return;
            }
        }
        else if (sType=='NonForSale')
        {
            var url = '<%= ResolveUrl("~/Webform/ManageSalesForecast/PLV_INPUT2.aspx") %>';
        }
        window.open(url + '?Skutype=' + TypeCell.value + '&Sapcode=' + SapCodeCell.value + '&SessionID=<%=Me.SessionID %>&VControl=<%=Me.VControl %>','','height=600px,toolbar=0,titlebar=0,resizable,status=1');
    }
    else
    {
        alert('Please click S or P or TTL section for one SKU in advance!!');
        return;
    }
}

function <%=Me.ClientID %>YearNext(n)
{
<% 'All以外的選項切換 year 無作用 %>
<% IF ProductHierarchyControl1.DisplayYear = MyObj.GetDDLSelectAllItem.Value Then %>
    var sheet = $get('SF_Spreadsheet1');
    var txtDailyInputYear = $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>');
    var result =  Number(txtDailyInputYear.value) + n ; 

    //var now=new Date();
    //var i = now.getFullYear();
    var i = '<%=Me.SFModel.SF_Year %>';
    if('<%=Me.SFModel.SF_Month %>'=='B')
    {
        var now = new Date(i,1,1);
        var mydate = new Date(i,1,1);
    }
    else
    {
        var now = new Date(i,'<%=Me.SFModel.SF_ReferMM %>',1);
        var mydate = new Date(i,'<%=Me.SFModel.SF_ReferMM %>',1);
    }
    var finalresult =result -i;
    //var mydate = new Date();

    mydate.setMonth(now.getMonth() + 15); 

    if(result > mydate.getFullYear()||result<i-1)
    {
        alert("It's out of range!");
    }
    else
    {

        switch (finalresult)
        {
//前一年的Act改用Pop Window顯示,Update By Angus 20101117
            case -1:
                    $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>').value=result;
                    sheet.ActiveSheet.Range("G1").Select();
                    sheet.ActiveWindow.ScrollColumn = sheet.ActiveCell.Column;   
                    break;   
            case 0:
                    $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>').value=result;
                    if('<%=Me.Session(Me.SessionID & "SF_DisplayYear") %>' == '')
                    {
                        sheet.ActiveSheet.Range("W1").Select();
                    }
                    else
                    {
                        sheet.ActiveSheet.Range(StartColumn).Select();
                    }
                    sheet.ActiveWindow.ScrollColumn = sheet.ActiveCell.Column;
                    break;
            case 1:
                    $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>').value=result;
                    sheet.ActiveSheet.Range("AN1").Select();
                    //sheet.ActiveSheet.Range("V1").Select();
                    sheet.ActiveWindow.ScrollColumn = sheet.ActiveCell.Column;
                    break; 
            case 2:
                    $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>').value=result;
                    sheet.ActiveSheet.Range("BB1").Select();
                    //sheet.ActiveSheet.Range("AK1").Select();
                    sheet.ActiveWindow.ScrollColumn = sheet.ActiveCell.Column  ;
                    break;  
            default:
                    alert("It's out of range!");        
         }    
     }
<% End If %>
}

function cloneListPrice(value)
{
    //複製值到右列
    
    var sheet = $get('SF_Spreadsheet1');

    //僅處理 list price,P.A(%),STD 列且欄位 >= V 且要為 FCST   
    if (sheet.range('E'+sheet.ActiveCell.Row) != 'P.A(%)' && sheet.range('E'+sheet.ActiveCell.Row) != 'List Price' && sheet.range('E'+sheet.ActiveCell.Row) != 'STD')
    {
        return;
    }
    else if (sheet.ActiveCell.Column < sheet.Range(StartColumn).Column)//原V1    
    {
        return;
    }
    else if (sheet.cells(3, sheet.ActiveCell.Column) != 'FCST')
    {
        return;
    }    

    var pricecell = sheet.ActiveCell.cells(1,1);

    for (var i = 0; i < 200; i++)
    {
        pricecell = pricecell.cells(1,2);
        
        //不可有公式且為FCST
        //if (pricecell.formula != '') continue;        
        var flagcell = sheet.cells(3, pricecell.Column);                       
        if (flagcell != 'FCST') continue;
        
        pricecell.value = value;
        pricecell.Interior.Color = 'Red';
    }
}

//開啟Stock視窗
function OpenLinkWindow(sType)
{
    var sheet = $get('SF_Spreadsheet1');
    //var hf_TargetRow = $get('<%= hf_TargetRow.ClientID %>');
    //var hf_TargetColumn = $get('<%= hf_TargetColumn.ClientID %>');
    //var TheCell = sheet.cells(hf_TargetRow.value,hf_TargetColumn.value);
    var TheCell = sheet.ActiveCell;
    var YearCell = sheet.cells(TheCell.row,TheCell.column+1);
    var LevelCell = sheet.cells(TheCell.row,1);
    var ReportMode = '<%= Me.Search2.ReportMode %>';

    if (TheCell.value == 'STOCK (D-1)')
    {
        var SapcodeCell = sheet.cells(TheCell.Row-3,TheCell.Column-2);                       
        var url = '<%= ResolveUrl("~/WebForm/ManageSalesForecast/Stock.aspx") %>' + '?Sapcode=' + SapcodeCell.value + '&SessionID=<%=Me.SessionID %>';        
        if(sType == "Stock")
        {
            url = url + "&Stock=Y"
            ShowContent('divStock',url);
        }
        else
        {
            HideContent('divStock');
            window.open(url,'',OpenInCenter(450,480) + ',left=0,top=0,toolbar=0,titlebar=0,location=center,resizable,scrollbars=Yes,status=1');
        }
    }
    else if (TheCell.value == 'Sell-In (D-1)')
    {
        var SapcodeCell = sheet.cells(TheCell.Row-4,TheCell.Column-2);                       
        var url = '<%= ResolveUrl("~/WebForm/ManageSalesForecast/SellIn.aspx") %>' + '?Sapcode=' + SapcodeCell.value + '&SessionID=<%=Me.SessionID %>';        
        if(sType == "Stock")
        {
            url = url + "&Stock=Y"
            ShowContent('divStock',url);
        }
        else
        {
            HideContent('divStock');
            window.open(url,'',OpenInCenter(450,400) + ',left=0,top=0,toolbar=0,titlebar=0,location=center,resizable,scrollbars=Yes,status=1');      
        }
    }
    else 
    {
        HideContent('divStock');
        if (LevelCell.value == 'SKU' && ReportMode!='2' && ReportMode!='3' && sType != "Stock")//2:Gross;3:Act
        {
            if (TheCell.value == 'S' || TheCell.value == 'P') 
            {
                var SapcodeCell = sheet.cells(TheCell.Row,TheCell.Column-3);                       
                //var url = '<%= ResolveUrl("~/WebForm/ManageSalesForecast/SkuByChannel.aspx") %>' + '?Sapcode=' + SapcodeCell.value+ '&Skutype=' + TheCell.value;
                var url = '<%= ResolveUrl("~/WebForm/ManageSalesForecast/ChannelSpectrumV2.aspx") %>' + '?Sapcode=' + SapcodeCell.value+ '&Skutype=' + TheCell.value+ '&rowindex=' + TheCell.row + '&SessionID=<%=Me.SessionID %>&VControl=<%=Me.VControl %>';
                //window.open(url,'',OpenInCenter(800,500) + ',toolbar=0,titlebar=0,resizable,scrollbars=Yes');
                //window.open(url,'',OpenInCenter(800,500));
                window.open(url);
            }
            else if (YearCell.value == 'Y' && (TheCell.value == 'PBOM' || TheCell.value == 'TTL'|| TheCell.value == 'Sell-Out-TTL')) //2:Gross;3:Act
            {
                var SapcodeCell;
                var SkuTypeValue;
                switch (TheCell.value)
                {
                    case 'PBOM':
                        SapcodeCell = sheet.cells(TheCell.Row-2,2); 
                        SkuTypeValue = TheCell.value;
                        break;      
                    case 'TTL':
                        SapcodeCell = sheet.cells(TheCell.Row-3,2); 
                        SkuTypeValue = TheCell.value; 
                        break;  
                    case 'Sell-Out-TTL':
                        SapcodeCell = sheet.cells(TheCell.Row-6,2); 
                        SkuTypeValue = 'SellOut';  
                        break; 
                }           
                var url = '<%= ResolveUrl("~/WebForm/ManageSalesForecast/ChannelSkuType.aspx") %>' + '?Sapcode=' + SapcodeCell.value+ '&Skutype=' + SkuTypeValue + '&rowindex=' + TheCell.row + '&SessionID=<%=Me.SessionID %>';
                window.open(url);
            }
    //        else if (YearCell.value == 'Y-1' && TheCell.value == 'Sell-Out-PBOM')
    //        {
    //            var SapcodeCell;
    //            var SkuTypeValue;
    //            switch (TheCell.value)
    //            {
    //                case 'Sell-Out-PBOM':
    //                    SapcodeCell = sheet.cells(TheCell.Row-6,2); 
    //                    SkuTypeValue = 'SellOutPBOM(Y-1)';  
    //                    break; 
    //            }           
    //            var url = '<%= ResolveUrl("~/WebForm/ManageSalesForecast/ChannelSkuType.aspx") %>' + '?Sapcode=' + SapcodeCell.value+ '&Skutype=' + SkuTypeValue + '&rowindex=' + TheCell.row + '&SessionID=<%=Me.SessionID %>';
    //            window.open(url);
    //        }
        }
    }
}

function OpenInCenter(width,height)
{
    var left   = (screen.width  - width)/2;
    var top    = (screen.height - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    return params;
}

function <%=Me.ClientID %>js_LoadCompleted(sheetid)
{
    $get(sheetid).activeSheet.protection.enabled = false;
    $get(sheetid).ActiveSheet.Columns.AutoFit();
    var ReportMode = '<%= Me.Search2.ReportMode %>';
    if (ReportMode=='2' || ReportMode=='3') //2:Gross;3:Act
    {
        $get(sheetid).activeSheet.cells.locked = true;
    }
    
    $get(sheetid).ActiveWindow.ActiveSheet.Protection.Enabled = true;   
    <%=Me.ClientID %>YearNext(0);
    
    MaxRow = $get(sheetid).ActiveSheet.UsedRange.Rows.Count 
    var sfRange = $get('BK_Spreadsheet1').Range("B4:B" + MaxRow);  
    var sfFromRange = $get(sheetid).Range("B4:B" + MaxRow);  
    sfRange.value = sfFromRange.value;
    //sfFromRange.Copy();
    //sfRange.Paste();
}

function <%=Me.ClientID %>SF_GetMemo()
{
        //有註解欄位才取資料
        var txtNotes = $get('<%=Search2.FindControl("txtNotes").ClientID %>');
        //if (txtNotes == undefined || '<%= Me.Search2.ReportMode %>'=='1') return;//1:Meeting
        if (txtNotes == undefined) return;//1:Meeting

        var btnUpload = $get('<%=Search2.FindControl("btnUpload").ClientID %>');

    var sheet = $get('SF_Spreadsheet1');
    
    var TargetCell = sheet.ActiveCell;
    var TopicCell = sheet.cells(3,TargetCell.column);
    var WeekCell = sheet.cells(4,TargetCell.column);
    var LevelNameCell = sheet.cells(TargetCell.row,1);                            

    //FCST、ACT才取Memo
    if ((TopicCell.value=='FCST' || TopicCell.value=='ACT') && LevelNameCell.value=='SKU' && WeekCell.value != 'YTD')
    {        
        btnUpload.disabled = false;
        txtNotes.disabled = false;
        var SapCodeRow=0;
        var SkuTypeCell = sheet.cells(TargetCell.row,5);
        var SkuYearCell = sheet.cells(TargetCell.row,6);
        var sf = new SFMemo();
        var SkuTypeCellValue = String(SkuTypeCell.value)+String(SkuYearCell.value);

        switch(SkuTypeCellValue)
        {
            case 'SY':
              SapCodeRow = TargetCell.row;
              SkuTypeCellValue = "S";
              break;
            case 'PY':
              SapCodeRow = TargetCell.row;
              SkuTypeCellValue = "P";
              break;
            case 'PBOMY':
              SapCodeRow = TargetCell.row-1;
              SkuTypeCellValue = "PBOM";
              break;
            case 'TTLY':
              SapCodeRow = TargetCell.row-2;
              SkuTypeCellValue = "TTL";
              break;
            case 'TTLY-1':
              SapCodeRow = TargetCell.row-3;
              SkuTypeCellValue = "TTL(Y-1)";
              break;
            case '%':
              SapCodeRow = TargetCell.row-4;
              SkuTypeCellValue = "%";
              break;
            case 'Sell-Out-TTLY':
              SapCodeRow = TargetCell.row-5;
              SkuTypeCellValue = "SellOut";
              break;
            case 'Sell-Out-TTLY-1':
              SapCodeRow = TargetCell.row-6;
              SkuTypeCellValue = "SellOut(Y-1)";
              break;
            case 'Sell-Out-PBOMY-1':
              SapCodeRow = TargetCell.row-7;
              SkuTypeCellValue = "SellOutPBOM(Y-1)";
              break;
            case 'P.A(%)Y':
              SapCodeRow = TargetCell.row-8;
              SkuTypeCellValue = "PAllow";
              break;
            case 'List PriceY':
              SapCodeRow = TargetCell.row-9;
              SkuTypeCellValue = "ListP";
              break;
            case 'STDY':
              SapCodeRow = TargetCell.row-10;
              SkuTypeCellValue = "STD";
              break;
            default:
              txtNotes.value = "";
              btnUpload.disabled = true;
              txtNotes.disabled = true;
              return;
        }
        sf.SkuType = SkuTypeCellValue;

        var SapCodeCell = sheet.cells(SapCodeRow,2);
        var MonthCell = sheet.cells(4,TargetCell.column);
        sf.SapCode = SapCodeCell.value.replace('<%= MyObj.GetAreaCode() %>','');
        sf.ChannelID = '<%= Me.SFModel.SF_Channel %>';

        var d = new Date(MonthCell.value);

        if (TopicCell.value=='FCST')
        {
            sf.MonthCode = '<%= Me.SFModel.SF_MonthCode %>';
            var now = new Date('<%=Me.SFModel.SF_Year %>',1,1);  
            sf.MonIndex = (d.getFullYear() - now.getFullYear()) * 12 + d.getMonth()+1;//js的月份是從0起算的，0~11共12個月
        }
        else//ACT
        {
            sf.MonthCode = String(d.getFullYear()) + 'A';
            sf.MonIndex = d.getMonth()+1;//js的月份是從0起算的，0~11共12個月
        }

        BLSService.GetSFMemoV2(sf,<%=Me.ClientID %>SF_ShowGetMemo);
    }
    else
    {
        txtNotes.value = "";
        btnUpload.disabled = true;
        txtNotes.disabled = true;
    }
}

function <%=Me.ClientID %>SF_ShowGetMemo(arg)
{
    var txtNotes = $get('<%=Search2.FindControl("txtNotes").ClientID %>');
    txtNotes.value = arg;
}

function <%=Me.ClientID %>SF_SaveMemo()
{
    var txtNotes = $get('<%=Search2.FindControl("txtNotes").ClientID %>');
    
    if(txtNotes.value.length>=1000)
    {
        alert('Comments is too long!!(Length:1000)');
        return;
    }
    
    var sheet = $get('SF_Spreadsheet1');
    var TargetCell = sheet.ActiveCell;
    var SapCodeRow=0;
    var SkuTypeCell = sheet.cells(TargetCell.row,5);
    var SkuYearCell = sheet.cells(TargetCell.row,6);
    var sf = new SFMemo();
    var SkuTypeCellValue = String(SkuTypeCell.value)+String(SkuYearCell.value);
    var TopicCell = sheet.cells(3,TargetCell.column);
    var WeekCell = sheet.cells(2,TargetCell.column);
    var LevelNameCell = sheet.cells(TargetCell.row,1);
    //FCST、ACT才取Memo
    if ((TopicCell.value=='FCST' || TopicCell.value=='ACT') && LevelNameCell.value=='SKU' && WeekCell.value !='YTD')
    {
        switch(SkuTypeCellValue)
        {
            case 'SY':
              SapCodeRow = TargetCell.row;
              SkuTypeCellValue = "S";
              break;
            case 'PY':
              SapCodeRow = TargetCell.row;
              SkuTypeCellValue = "P";
              break;
            case 'PBOMY':
              SapCodeRow = TargetCell.row-1;
              SkuTypeCellValue = "PBOM";
              break;
            case 'TTLY':
              SapCodeRow = TargetCell.row-2;
              SkuTypeCellValue = "TTL";
              break;
            case 'TTLY-1':
              SapCodeRow = TargetCell.row-3;
              SkuTypeCellValue = "TTL(Y-1)";
              break;
            case '%':
              SapCodeRow = TargetCell.row-4;
              SkuTypeCellValue = "%";
              break;
            case 'Sell-Out-TTLY':
              SapCodeRow = TargetCell.row-5;
              SkuTypeCellValue = "SellOut";
              break;
            case 'Sell-Out-TTLY-1':
              SapCodeRow = TargetCell.row-6;
              SkuTypeCellValue = "SellOut(Y-1)";
              break;
            case 'Sell-Out-PBOMY-1':
              SapCodeRow = TargetCell.row-7;
              SkuTypeCellValue = "SellOutPBOM(Y-1)";
              break;
            case 'P.A(%)Y':
              SapCodeRow = TargetCell.row-8;
              SkuTypeCellValue = "PAllow";
              break;
            case 'List PriceY':
              SapCodeRow = TargetCell.row-9;
              SkuTypeCellValue = "ListP";
              break;
            case 'STDY':
              SapCodeRow = TargetCell.row-10;
              SkuTypeCellValue = "STD";
              break;
            default:
              txtNotes.value = "";
              btnUpload.disabled = true;
              txtNotes.disabled = true;
              return;
        }
        sf.SkuType = SkuTypeCellValue;
        var SapCodeCell = sheet.cells(SapCodeRow,2);
        var MonthCell = sheet.cells(4,TargetCell.column);
        sf.SapCode = SapCodeCell.value.replace('<%= MyObj.GetAreaCode() %>','');
        sf.ChannelID = '<%= Me.SFModel.SF_Channel %>';
        sf.Memo = txtNotes.value;
        
        var d = new Date(MonthCell.value);

        if (TopicCell.value=='FCST')
        {
            sf.MonthCode = '<%= Me.SFModel.SF_MonthCode %>';
            var now = new Date('<%=Me.SFModel.SF_Year %>',1,1);  
            sf.MonIndex = (d.getFullYear() - now.getFullYear()) * 12 + d.getMonth()+1;//js的月份是從0起算的，0~11共12個月
        }
        else//ACT
        {
            sf.MonthCode = String(d.getFullYear()) + 'A';
            sf.MonIndex = d.getMonth()+1;//js的月份是從0起算的，0~11共12個月
        }
        
        var OldStatus = TargetCell.locked;
        TargetCell.locked = false;
        if (txtNotes.value != '')
        {
            TargetCell.Borders.Color = 'Red';
        }
        else
        {
            TargetCell.Borders.Color = '';
        }
        TargetCell.locked = OldStatus;
        BLSService.SaveSFMemoV2(sf,<%=Me.ClientID %>SF_ShowSaveMemo);
    }
    else
    {
        txtNotes.value = "";
        btnUpload.disabled = true;
        txtNotes.disabled = true;
    }
}

function <%=Me.ClientID %>SF_ShowSaveMemo(arg)
{
    alert(arg);
}

</script>

<script type="text/javascript" language="JavaScript">
    var cX = 0; var cY = 0; var rX = 0; var rY = 0;
    function UpdateCursorPosition(e) { cX = e.pageX; cY = e.pageY; }
    function UpdateCursorPositionDocAll(e) { cX = event.clientX; cY = event.clientY; }
    //if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
    //else { document.onmousemove = UpdateCursorPosition; }

    function AssignPosition(d) {
        if (self.pageYOffset) {
            rX = self.pageXOffset;
            rY = self.pageYOffset;
        }
        else if (document.documentElement && document.documentElement.scrollTop) {
            rX = document.documentElement.scrollLeft;
            rY = document.documentElement.scrollTop;
        }
        else if (document.body) {
            rX = document.body.scrollLeft;
            rY = document.body.scrollTop;
        }
        if (document.all) {
            cX += rX;
            cY += rY;
        }
        d.style.left = (cX + 5) + "px";
        d.style.top = (cY - 200) + "px";
    }
    function HideContent(d) {
        if (d.length < 1) { return; }
        document.getElementById(d).style.display = "none";
    }

    function ShowContent(d, url) {
        return//return
        var dd = document.getElementById(d);
        AssignPosition(dd);
        dd.style.display = "block";
        var Myiframe = $get('IFRAME1');
        Myiframe.src = url;
    }

    function ReverseContentDisplay(d) {
        if (d.length < 1) { return; }
        var dd = document.getElementById(d);
        AssignPosition(dd);
        if (dd.style.display == "none") { dd.style.display = "block"; }
        else { dd.style.display = "none"; }
    }

</script>

<div id="divStock" style="display: none; overflow: auto; z-index: 9999; left: 8px;
    width: 500px; position: absolute; top: 8px; height: 500px">
    <iframe scrolling="no" frameborder="0" style="background-color: #4E333B" width="100%"
        height="100%" id="IFRAME1"></iframe>
</div>

<script type="text/vbscript">
Sub SF_Spreadsheet1_LoadCompleted()
    Call <%=Me.ClientID %>js_LoadCompleted("SF_Spreadsheet1")    
End Sub

'OK,編輯狀態結束事件


'OK,鍵盤輸入事件
'Sub SF_Spreadsheet1_KeyPress(ByVal KeyCode)
'    set WorkSheet_SS = document.getElementById("SF_Spreadsheet1")
'    if WorkSheet_SS.ActiveCell.Interior.Color <> vbMagenta then
'        WorkSheet_SS.ActiveCell.Interior.Color = vbMagenta
'    end if   
'End Sub

'OK,鍵盤上下左右事件
Sub SF_Spreadsheet1_KeyDown(ByVal KeyCode,ByVal Shift)  
    '紀錄現在的值
    set hf_NowValue = document.getElementById("<%= hf_NowValue.ClientID %>")
    set WorkSheet_SS = document.getElementById("SF_Spreadsheet1")
    hf_NowValue.value = WorkSheet_SS.ActiveCell.Value  
    call <%=Me.ClientID %>SF_GetMemo()
End Sub
        
'Sub SF_Spreadsheet1_MouseOver(ByVal Button, ByVal Shift, ByVal Target)
'    '紀錄現在的值
'          
'    set hf_TargetRow = document.getElementById("<%= hf_TargetRow.ClientID %>")
'    set hf_TargetColumn = document.getElementById("<%= hf_TargetColumn.ClientID %>")
'    
'    hf_TargetRow.value = Target.Row 
'    hf_TargetColumn.value = Target.Column

'    call OpenLinkWindow("Stock")
'End Sub

'OK,滑鼠點擊事件
Sub SF_Spreadsheet1_Click()
    '紀錄現在的值
    'Exit Sub
'    set hf_NowValue = document.getElementById("<%= hf_NowValue.ClientID %>")
'    set WorkSheet_SS = document.getElementById("SF_Spreadsheet1")
'    set ActiveCell = WorkSheet_SS.ActiveCell
'    hf_NowValue.value = ActiveCell.Value
'        
'    set hf_TargetRow = document.getElementById("<%= hf_TargetRow.ClientID %>")
'    set hf_TargetColumn = document.getElementById("<%= hf_TargetColumn.ClientID %>")
    
    'hf_TargetRow.value = ActiveCell.Row 
    'hf_TargetColumn.value = ActiveCell.Column

    call OpenLinkWindow()
    call <%=Me.ClientID %>SF_GetMemo()
End Sub


'複製貼上
Sub SF_Spreadsheet1_SheetChange(ByVal Sh, ByVal Target)
    set sheet = document.getElementById("SF_Spreadsheet1")
    sheet.EnableEvents = false
    
    '若為單一Cell,則有修改才做動作
    if sheet.Selection.count=1 then
        set hf_NowValue = document.getElementById("<%= hf_NowValue.ClientID %>")
        if Target.Locked<>true then
            if Cstr(Target.value)<>Cstr(hf_NowValue.value) then
                sheet.ActiveCell.Interior.Color = vbRed
                call <%= Me.ClientID %>AddSaveIndex(sheet.ActiveCell.Row)
                call cloneListPrice(Target.value)
            end if
        end if
    elseif sheet.Selection.count>1 then
        set MySelection=sheet.Selection
        For Each rng In sheet.Selection
            if rng.Locked<>true then
                rng.Interior.Color = vbRed
                rng.Select()
                call <%= Me.ClientID %>AddSaveIndex(sheet.ActiveCell.Row)
                call cloneListPrice(rng.value)
            end if
        Next
        MySelection.select()
    end if
    
    sheet.EnableEvents = true
End Sub

     
</script>

<script type="text/javascript">

        data = new Array();
        
        function <%=Me.ClientID %>saveData()
        {
            if (data.length == 0)
            {
                alert("No data changed.");
                return;
            }
                    
            var sheet = $get('SF_Spreadsheet1');
            
            //僅上傳有異動的資料行
            for (var i=0; i<data.length; i++)
            {
                var sf = data[i];
                
                switch (sheet.Range("E"+sf.RefIndex).value)
                {
                    case "S":
                        sf.SkuType = "S"
                        sf.SapCode = sheet.Range("B"+sf.RefIndex).value.replace('<%= MyObj.GetAreaCode() %>','');
                        break;
                    case "P":
                        sf.SkuType = "P"
                        sf.SapCode = sheet.Range("B"+sf.RefIndex).value.replace('<%= MyObj.GetAreaCode() %>','');
                        break;
                    case "P.A(%)":
                        sf.SkuType = "PAllow"
                        sf.SapCode = sheet.Range("B"+(sf.RefIndex-8)).value.replace('<%= MyObj.GetAreaCode() %>','');
                        break;                                    
                    case "List Price":
                        sf.SkuType = "ListP"
                        sf.SapCode = sheet.Range("B"+(sf.RefIndex-9)).value.replace('<%= MyObj.GetAreaCode() %>','');
                        break;
                    case "STD":
                        sf.SapCode = sheet.Range("B"+(sf.RefIndex-10)).value.replace('<%= MyObj.GetAreaCode() %>','');
                        sf.SkuType = "STD"                                    
                        break;    
                        
                }  
                                            
                //從報表所在年度的第一個月份開始
                var currFCSTCell = sheet.Range("G3");//原V3
                var currmon = 1;                

                //以年為單位開始取值 (最長4年)
                for (var yy=0; yy<4; yy++)
                {    
                    if (currFCSTCell.value == undefined) break;

                    for (var mon = 0; mon < 12; mon++)
                    {                                                                        
                        if (currFCSTCell.value == 'FCST')
                        {
                                                                      
                            //sf.SapCode = sheet.Range("B"+sf.RefIndex).value;
                            //sf.SkuType = sheet.Range("E"+sf.RefIndex).value;
                            var MonthCell = sheet.cells(4,currFCSTCell.column);
                            var d = new Date(MonthCell.value);
                            var now = new Date('<%=Me.SFModel.SF_Year %>',1,1);  
                            currmon = (d.getFullYear() - now.getFullYear()) * 12 + d.getMonth()+1;//js的月份是從0起算的，0~11共12個月
                            
                            sf['Mon'+currmon] = sheet.cells(sf.RefIndex, currFCSTCell.column).value;
                            //用cell顏色判斷有無修改
                            if(sheet.cells(sf.RefIndex, currFCSTCell.column).Interior.Color == '255')  
                            {
                                sf['Mon'+currmon+'Change'] = 'Y';
                                sheet.cells(sf.RefIndex, currFCSTCell.column).Interior.Color = '#FFFFCC';//清除紅色標記
                            }             
                            else
                            {
                                sf['Mon'+currmon+'Change'] = 'N';
                            }                                                   
                        }
                        
                        currFCSTCell = currFCSTCell.Cells(1,2); //下一個月
                        //currmon++;                        
                    }
                    
                    //跳至下一年的第一個月份 cell
                    currFCSTCell = currFCSTCell.cells(1,5);
                }
            }
            
            
            if('<%= Me.SFModel.IsMutiChannel %>'=='True')
            {
                SFService.SaveDataByAllChannel(data , '<%= Me.SessionID %>', <%=Me.ClientID %>OnComplete);
            }
            else
            {
                SFService.SaveData(data , '<%= Me.SessionID %>' , <%=Me.ClientID %>OnComplete);
            }
            data = new Array();
        }
        
        function <%=Me.ClientID %>AddSaveIndex(rowIndex)
        {
            //確認此 index 是否已被儲存
            for(var i=0; i<data.length; i++)
            {
                if (data[i].RefIndex == rowIndex) return;
            }
            
            var sf = new SFReport();        
        
            sf.RefIndex = rowIndex;
            data[data.length] = sf;
        }
    
		function <%=Me.ClientID %>OnComplete(arg)
		{
			alert(arg);
		}

		function <%=Me.ClientID %>SF_FocusFind()
		{
			if(event.keyCode == 13)
			{
			    $get('<%=Search2.FindControl("btnFindProd").ClientID %>').focus();
			    return false;
			}
		}
</script>

<My:ProductHierarchyControl ID="ProductHierarchyControl1" runat="server" />
<br />
<asp:PlaceHolder ID="pl1" runat="server" Visible="false">
    <div style="background-color: #351D26">
        <fieldset id="pnlData" runat="server" style="border-color: #4E333B;">
            <legend class="white2">
                <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:pnlData.GroupingText%>" />
            </legend>
            <MyReport:Search2View ID="Search2" runat="server">
                <NormalSearchTemplate>
                    <table align="left" width="100%" border="0" cellspacing="0">
                        <tr>
                            <td align="left">
                                <table align="left" width="100%" border="0" cellspacing="0">
                                    <tr>
                                        <td align="left">
                                                <asp:Label ID="lblYear" runat="server" meta:resourcekey="lblYear"></asp:Label>
                                                <input type="button" id="btnPrev" class="button" runat="server" value="<%$ Resources:btnPrev.Text %>"
                                                    enabled='<%# ProductHierarchyControl1.DisplayYear = MyObj.GetDDLSelectAllItem.Value %>'
                                                    onclick='<%# Me.ClientID + "YearNext(-1);return false;" %>' />
                                                <asp:TextBox ID="txtDailyInputYear" runat="server" Width="30px" Enabled="false"></asp:TextBox>
                                                <input type="button" id="btnNext" class="button" runat="server" value="<%$ Resources:btnNext.Text %>"
                                                    enabled='<%# ProductHierarchyControl1.DisplayYear = MyObj.GetDDLSelectAllItem.Value %>'
                                                    onclick='<%# Me.ClientID + "YearNext(1);return false;" %>' />
                                            <input type="button" id="btnGrossSales" class="button2" runat="server" onclick="openSpecWindow('GrossSales');return false;"
                                                value="<%$ Resources:btnGrossSales.Text %>" />
                                            <input type="button" id="btnACT" visible="false" class="button2" runat="server" onclick="openSpecWindow('Act');return false;"
                                                value='<%# Session(Me.SessionID & "SF_Year") - 1 & " Act" %>' />
                                            <input type="button" id="btnPercentage" style="width: 15px" class="button" runat="server"
                                                value="<%$ Resources:btnPercentage.Text %>" onclick="openSpecWindow('Percentage');" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td align="left">
                                <asp:Label ID="lblNotes" runat="server" meta:resourcekey="lblNotes"></asp:Label>
                                <asp:TextBox ID="txtNotes" TextMode="MultiLine" Rows="2" Columns="38" runat="server"
                                    Width="375px"></asp:TextBox>
                                <input type="button" id="btnUpload" class="button" runat="server" value="<%$ Resources:btnUpload.Text %>"
                                    onclick='<%# Me.ClientID + "SF_SaveMemo();return false;" %>' />
                            </td>
                        </tr>
                        <tr>
                            <td align="left" colspan="2">
                                <asp:Label ID="lblFindProd" runat="server" meta:resourcekey="lblFindProd"></asp:Label>
                                <asp:TextBox ID="txtFindProd" OnKeyPress='<%# Me.ClientID + "SF_FocusFind();" %>'
                                    runat="server"></asp:TextBox>
                                <input type="button" id="btnFindProd" class="button" runat="server" value="<%$ Resources:btnFindProd.Text %>"
                                    onclick='<%# Me.ClientID + "SF_FindProd();return false;" %>' />
                                <input type="button" id="btnPSpectrum" class="button2" runat="server" value="<%$ Resources:report,btnPSpectrum %>"
                                    onclick="openWindow('ProductSpectrum');" />
                                <input type="button" id="btnPLV" class="button2" runat="server" value="<%$ Resources:btnPLV.Text %>"
                                    onclick="openWindow('NonForSale');" />
                                <asp:Label ID="lblTransferPLV" runat="server" meta:resourcekey="lblTransferPLV"></asp:Label>
                                <asp:DropDownList ID="ddlTransferPLV" runat="server">
                                </asp:DropDownList>
                                <input type="button" id="btnTransferPLV" class="button" runat="server" value="<%$ Resources:btnTransferPLV.Text %>"
                                    onclick="openSpecWindow('TransferPLV');" />
                                <asp:Button ID="btnRefreshSF" runat="server" Visible="false" Text="Refresh" OnClick="btnRefreshSF_Click" />
                                <input type="button" id="btnSave" class="button" runat="server" onclick='<%# Me.ClientID + "saveData()"%>'
                                    value="<%$ Resources:btnSave.Text %>" />
                            </td>
                        </tr>
                    </table>
                </NormalSearchTemplate>
                <MeetingSearchTemplate>
                    <table align="center" width="100%" border="0" cellspacing="0">
                        <tr>
                            <td>
                                <table width="100%" border="0" cellspacing="0">
                                    <tr>
                                        <asp:PlaceHolder ID="plRange" runat="server" Visible='<%# ProductHierarchyControl1.DisplayYear = MyObj.GetDDLSelectAllItem.Value %>'>
                                            <td align="left">
                                                <asp:Label ID="lblYear" runat="server" meta:resourcekey="lblYear"></asp:Label>
                                            </td>
                                            <td align="left">
                                                <input type="button" id="btnPrev" class="button" runat="server" value="<%$ Resources:btnPrev.Text %>"
                                                    onclick='<%# Me.ClientID + "YearNext(-1);return false;" %>' />
                                                <asp:TextBox ID="txtDailyInputYear" runat="server" Width="30px" Enabled="false"></asp:TextBox>
                                                <input type="button" id="btnNext" class="button" runat="server" value="<%$ Resources:btnNext.Text %>"
                                                    onclick='<%# Me.ClientID + "YearNext(1);return false;" %>' />
                                                <input type="button" id="btnGrossSales" class="button2" runat="server" onclick="openSpecWindow('GrossSales');return false;"
                                                    value="<%$ Resources:btnGrossSales.Text %>" />
                                            </td>
                                        </asp:PlaceHolder>
                                        <td align="left">
                                            <asp:Label ID="lblNotes" runat="server" meta:resourcekey="lblNotes"></asp:Label>
                                        </td>
                                        <td align="left">
                                            <asp:TextBox ID="txtNotes" TextMode="MultiLine" Rows="2" Columns="38" runat="server"
                                                Width="375px"></asp:TextBox>
                                            <input type="button" id="btnUpload" class="button" runat="server" value="<%$ Resources:btnUpload.Text %>"
                                                onclick='<%# Me.ClientID + "SF_SaveMemo();return false;" %>' />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <table width="100%" border="0" cellspacing="0">
                                    <tr>
                                        <td align="left">
                                            <asp:Label ID="lblFindProd" runat="server" meta:resourcekey="lblFindProd"></asp:Label>
                                            <asp:TextBox ID="txtFindProd" OnKeyPress='<%# Me.ClientID + "SF_FocusFind();" %>'
                                                runat="server"></asp:TextBox>
                                            <input type="button" id="btnFindProd" class="button" runat="server" value="<%$ Resources:btnFindProd.Text %>"
                                                onclick='<%# Me.ClientID + "SF_FindProd();return false;" %>' />
                                            <input type="button" id="btnPercentage" style="width: 15px" class="button" runat="server"
                                                value="<%$ Resources:btnPercentage.Text %>" onclick="openSpecWindow('Percentage');" />
                                            <input type="button" id="btnPSpectrum" visible="false" class="button2" runat="server"
                                                value="<%$ Resources:report,btnPSpectrum %>" onclick="openWindow('ProductSpectrum');" />
                                            <input type="button" id="btnPLV" visible="false" class="button2" runat="server" value="<%$ Resources:btnPLV.Text %>"
                                                onclick="openWindow('NonForSale');" />
                                            <asp:Label ID="lblTransferPLV" Visible="false" runat="server" meta:resourcekey="lblTransferPLV"></asp:Label>
                                            <asp:DropDownList ID="ddlTransferPLV" Visible="false" runat="server">
                                            </asp:DropDownList>
                                            <input type="button" id="btnTransferPLV" visible="false" class="button" runat="server"
                                                value="<%$ Resources:btnTransferPLV.Text %>" onclick="openSpecWindow('TransferPLV');" />
                                        </td>
                                        <td align="right">
                                            <asp:Button ID="btnRefreshSF" runat="server" Visible="false" Text="Refresh" OnClick="btnRefreshSF_Click" />
                                            <input type="button" id="btnSave" class="button" runat="server" onclick='<%# Me.ClientID + "saveData()"%>'
                                                value="<%$ Resources:btnSave.Text %>" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </MeetingSearchTemplate>
                <GrossSearchTemplate>
                    <table align="center" width="100%" border="0" cellspacing="0">
                        <asp:PlaceHolder ID="meeting_pl1" runat="server" Visible="false">
                            <tr>
                                <td align="right">
                                    <asp:Label ID="lblVersion" runat="server" meta:resourcekey="lblVersion" Text="Version："></asp:Label>
                                </td>
                                <td align="left">
                                    <asp:TextBox ID="txtVersion" Enabled="false" Columns="60" runat="server"></asp:TextBox>
                                </td>
                                <td align="right">
                                    <asp:Label ID="lblNotes" runat="server" meta:resourcekey="lblNotes"></asp:Label>
                                </td>
                                <td align="left" rowspan="3" valign="top">
                                    <asp:TextBox ID="txtNotes" TextMode="MultiLine" Rows="2" Columns="38" runat="server"></asp:TextBox>
                                    <input type="button" id="btnUpload" class="button" runat="server" value="<%$ Resources:btnUpload.Text %>"
                                        onclick='<%# Me.ClientID + "SF_SaveMemo();return false;" %>' />
                                </td>
                            </tr>
                        </asp:PlaceHolder>
                        <tr>
                            <asp:PlaceHolder ID="plRange" runat="server" Visible='<%# ProductHierarchyControl1.DisplayYear = MyObj.GetDDLSelectAllItem.Value %>'>
                                <td align="right">
                                    <asp:Label ID="lblYear" runat="server" meta:resourcekey="lblYear"></asp:Label>
                                </td>
                                <td align="left" colspan="3">
                                    <input type="button" id="btnPrev" class="button" runat="server" value="<%$ Resources:btnPrev.Text %>"
                                        onclick='<%# Me.ClientID + "YearNext(-1);return false;" %>' />
                                    <asp:TextBox ID="txtDailyInputYear" runat="server" Width="30px" Enabled="false"></asp:TextBox>
                                    <input type="button" id="btnNext" class="button" runat="server" value="<%$ Resources:btnNext.Text %>"
                                        onclick='<%# Me.ClientID + "YearNext(1);return false;" %>' />
                                </td>
                            </asp:PlaceHolder>
                            <td align="right">
                                <asp:Label ID="lblFindProd" runat="server" meta:resourcekey="lblFindProd"></asp:Label>
                            </td>
                            <td colspan="2">
                                <asp:TextBox ID="txtFindProd" OnKeyPress='<%# Me.ClientID + "SF_FocusFind();" %>'
                                    runat="server"></asp:TextBox>
                                <input type="button" id="btnFindProd" class="button" runat="server" value="<%$ Resources:btnFindProd.Text %>"
                                    onclick='<%# Me.ClientID + "SF_FindProd();return false;" %>' />
                                <input type="button" id="btnPercentage" visible="false" style="width: 15px" class="button"
                                    runat="server" value="<%$ Resources:btnPercentage.Text %>" onclick="openSpecWindow('Percentage');" />
                            </td>
                            <td align="left" colspan="1">
                                <asp:Button ID="btnRefreshSF" runat="server" Text="Refresh" OnClick="btnRefreshSF_Click" />
                                <asp:Button ID="btnSave" runat="server" Visible="false" OnClientClick="return false;"
                                    meta:resourcekey="btnSave" />
                            </td>
                        </tr>
                        <asp:PlaceHolder ID="meeting_pl2" runat="server" Visible="false">
                            <tr>
                                <td align="right">
                                </td>
                                <td colspan="2">
                                    <input type="button" id="btnCSpectrum" class="button2" runat="server" value="<%$ Resources:report,btnCSpectrum %>"
                                        onclick="openWindow('ChannelSpectrum');" />
                                    <input type="button" id="btnPSpectrum" class="button2" runat="server" value="<%$ Resources:report,btnPSpectrum %>"
                                        onclick="openWindow('ProductSpectrum');" />
                                    <input type="button" id="btnPLV" class="button2" runat="server" value="<%$ Resources:btnPLV.Text %>"
                                        onclick="openWindow('NonForSale');" />
                                </td>
                                <td align="left" colspan="2">
                                    <table>
                                        <tr>
                                            <td align="left">
                                                <asp:Label ID="lblTransferPLV" runat="server" meta:resourcekey="lblTransferPLV"></asp:Label>
                                                <asp:DropDownList ID="ddlTransferPLV" runat="server">
                                                </asp:DropDownList>
                                                <input type="button" id="btnTransferPLV" class="button" runat="server" value="<%$ Resources:btnTransferPLV.Text %>"
                                                    onclick="openSpecWindow('TransferPLV');" />
                                            </td>
                                            <td align="right">
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </asp:PlaceHolder>
                    </table>
                </GrossSearchTemplate>
                <ActSearchTemplate>
                    <table align="center" width="100%" border="0" cellspacing="0">
                        <asp:PlaceHolder ID="meeting_pl1" runat="server" Visible="false">
                            <tr>
                                <td align="right">
                                    <asp:Label ID="lblVersion" runat="server" meta:resourcekey="lblVersion" Text="Version："></asp:Label>
                                </td>
                                <td align="left">
                                    <asp:TextBox ID="txtVersion" Enabled="false" Columns="60" runat="server"></asp:TextBox>
                                </td>
                                <td align="right">
                                    <asp:Label ID="lblNotes" runat="server" meta:resourcekey="lblNotes"></asp:Label>
                                </td>
                                <td align="left" rowspan="3" valign="top">
                                    <asp:TextBox ID="txtNotes" TextMode="MultiLine" Rows="2" Columns="38" runat="server"></asp:TextBox>
                                    <input type="button" id="btnUpload" class="button" runat="server" value="<%$ Resources:btnUpload.Text %>"
                                        onclick='<%# Me.ClientID + "SF_SaveMemo();return false;" %>' />
                                </td>
                            </tr>
                        </asp:PlaceHolder>
                        <tr>
                            <asp:PlaceHolder ID="plRange" runat="server" Visible='<%# ProductHierarchyControl1.DisplayYear = MyObj.GetDDLSelectAllItem.Value %>'>
                                <td align="right">
                                    <asp:Label ID="lblYear" runat="server" Visible="false" meta:resourcekey="lblYear"></asp:Label>
                                </td>
                                <td align="left" style="display: none">
                                    <input type="button" id="btnPrev" class="button" runat="server" value="<%$ Resources:btnPrev.Text %>"
                                        onclick='<%# Me.ClientID + "YearNext(-1);return false;" %>' />
                                    <asp:TextBox ID="txtDailyInputYear" runat="server" Width="30px" Enabled="false"></asp:TextBox>
                                    <input type="button" id="btnNext" class="button" runat="server" value="<%$ Resources:btnNext.Text %>"
                                        onclick='<%# Me.ClientID + "YearNext(1);return false;" %>' />
                                </td>
                            </asp:PlaceHolder>
                            <td align="right">
                                <asp:Label ID="lblFindProd" runat="server" meta:resourcekey="lblFindProd"></asp:Label>
                            </td>
                            <td>
                                <asp:TextBox ID="txtFindProd" OnKeyPress='<%# Me.ClientID + "SF_FocusFind();" %>'
                                    runat="server"></asp:TextBox>
                                <input type="button" id="btnFindProd" class="button" runat="server" value="<%$ Resources:btnFindProd.Text %>"
                                    onclick='<%# Me.ClientID + "SF_FindProd();return false;" %>' />
                                <input type="button" id="btnPercentage" visible="false" style="width: 15px" class="button"
                                    runat="server" value="<%$ Resources:btnPercentage.Text %>" onclick="openSpecWindow('Percentage');" />
                            </td>
                            <td align="left">
                                <asp:Button ID="btnRefreshSF" runat="server" Text="Refresh" OnClick="btnRefreshSF_Click" />
                                <asp:Button ID="btnSave" runat="server" Visible="false" OnClientClick="return false;"
                                    meta:resourcekey="btnSave" />
                            </td>
                        </tr>
                        <asp:PlaceHolder ID="meeting_pl2" runat="server" Visible="false">
                            <tr>
                                <td align="right">
                                </td>
                                <td colspan="2">
                                    <input type="button" id="btnCSpectrum" class="button2" runat="server" value="<%$ Resources:report,btnCSpectrum %>"
                                        onclick="openWindow('ChannelSpectrum');" />
                                    <input type="button" id="btnPSpectrum" class="button2" runat="server" value="<%$ Resources:report,btnPSpectrum %>"
                                        onclick="openWindow('ProductSpectrum');" />
                                    <input type="button" id="btnPLV" class="button2" runat="server" value="<%$ Resources:btnPLV.Text %>"
                                        onclick="openWindow('NonForSale');" />
                                </td>
                                <td align="left" colspan="2">
                                    <table>
                                        <tr>
                                            <td align="left">
                                                <asp:Label ID="lblTransferPLV" runat="server" meta:resourcekey="lblTransferPLV"></asp:Label>
                                                <asp:DropDownList ID="ddlTransferPLV" runat="server">
                                                </asp:DropDownList>
                                                <input type="button" id="btnTransferPLV" class="button" runat="server" value="<%$ Resources:btnTransferPLV.Text %>"
                                                    onclick="openSpecWindow('TransferPLV');" />
                                            </td>
                                            <td align="right">
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </asp:PlaceHolder>
                    </table>
                </ActSearchTemplate>
                <FcstSearchTemplate>
                    <table align="center" width="100%" border="0" cellspacing="0">
                        <tr>
                            <td align="left" colspan="6">
                                <table width="100%" border="0" cellspacing="0">
                                    <tr>
                                        <td align="left">
                                            <asp:Label ID="lblYear" runat="server" meta:resourcekey="lblYear"></asp:Label>
                                        </td>
                                        <td align="left">
                                            <input type="button" id="btnPrev" visible="false" class="button" runat="server" value="<%$ Resources:btnPrev.Text %>"
                                                onclick='<%# Me.ClientID + "YearNext(-1);return false;" %>' />
                                            <asp:TextBox ID="txtDailyInputYear" Visible="false" runat="server" Width="30px" Enabled="false"></asp:TextBox>
                                            <input type="button" id="btnNext" visible="false" class="button" runat="server" value="<%$ Resources:btnNext.Text %>"
                                                onclick='<%# Me.ClientID + "YearNext(1);return false;" %>' />
                                            <input type="button" id="btnGrossSales" class="button2" runat="server" onclick="openSpecWindow('GrossSales');return false;"
                                                value="<%$ Resources:btnGrossSales.Text %>" />
                                            <input type="button" id="btnACT" visible="false" class="button2" runat="server" onclick="openSpecWindow('Act');return false;"
                                                value='<%# Session(Me.SessionID & "SF_Year") - 1 & " Act" %>' />
                                            <input type="button" id="btnPercentage" style="width: 15px" class="button" runat="server"
                                                value="<%$ Resources:btnPercentage.Text %>" onclick="openSpecWindow('Percentage');" />
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lblNotes" runat="server" meta:resourcekey="lblNotes"></asp:Label>
                                        </td>
                                        <td align="left">
                                            <asp:TextBox ID="txtNotes" TextMode="MultiLine" Rows="2" Columns="38" runat="server"
                                                Width="375px"></asp:TextBox>
                                            <input type="button" id="btnUpload" class="button" runat="server" value="<%$ Resources:btnUpload.Text %>"
                                                onclick='<%# Me.ClientID + "SF_SaveMemo();return false;" %>' />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td align="left">
                                <asp:Label ID="lblFindProd" runat="server" meta:resourcekey="lblFindProd"></asp:Label>
                            </td>
                            <td align="left" colspan="5">
                                <asp:TextBox ID="txtFindProd" OnKeyPress='<%# Me.ClientID + "SF_FocusFind();" %>'
                                    runat="server"></asp:TextBox>
                                <input type="button" id="btnFindProd" class="button" runat="server" value="<%$ Resources:btnFindProd.Text %>"
                                    onclick='<%# Me.ClientID + "SF_FindProd();return false;" %>' />
                                <input type="button" id="btnPSpectrum" class="button2" runat="server" value="<%$ Resources:report,btnPSpectrum %>"
                                    onclick="openWindow('ProductSpectrum');" />
                                <input type="button" id="btnPLV" class="button2" runat="server" value="<%$ Resources:btnPLV.Text %>"
                                    onclick="openWindow('NonForSale');" />
                                <asp:Label ID="lblTransferPLV" runat="server" meta:resourcekey="lblTransferPLV"></asp:Label>
                                <asp:DropDownList ID="ddlTransferPLV" runat="server">
                                </asp:DropDownList>
                                <input type="button" id="btnTransferPLV" class="button" runat="server" value="<%$ Resources:btnTransferPLV.Text %>"
                                    onclick="openSpecWindow('TransferPLV');" />
                                <asp:Button ID="btnRefreshSF" runat="server" Visible="false" Text="Refresh" OnClick="btnRefreshSF_Click" />
                                <input type="button" id="btnSave" class="button" runat="server" onclick='<%# Me.ClientID + "saveData()"%>'
                                    value="<%$ Resources:btnSave.Text %>" />
                            </td>
                        </tr>
                    </table>
                </FcstSearchTemplate>
            </MyReport:Search2View>
        </fieldset>
    </div>
    <asp:HiddenField ID="hf_FindProd" runat="server" />
    <asp:HiddenField ID="hf_MemoData" runat="server" />
    <asp:HiddenField ID="hf_NowAddress" runat="server" />
    <asp:HiddenField ID="hf_NowValue" runat="server" />
    <asp:HiddenField ID="hf_YearNow" runat="server" />
    <asp:HiddenField ID="hf_Unit" runat="server" />
    <asp:HiddenField ID="hf_Gross" runat="server" />
    <asp:HiddenField ID="hf_ColumnCount" runat="server" />
    <asp:HiddenField ID="hf_SapCode" runat="server" />
    <asp:HiddenField ID="hf_TargetRow" runat="server" Value="1" />
    <asp:HiddenField ID="hf_TargetColumn" runat="server" Value="1" />
    <object id="SF_Spreadsheet1" classid="CLSID:0002E559-0000-0000-C000-000000000046"
        width="100%" height="515px" standby="Loading">
        <param name="DataType" value="XMLURL" />
        <param name="XMLURL" value="<%= Me.ReportXML %>" />
        <param name="AutoFit" value="0" />
    </object>
    <object id="BK_Spreadsheet1" classid="CLSID:0002E559-0000-0000-C000-000000000046"
        width="0%" height="0px" standby="Loading">
    </object>

    <script type="text/vbscript">
    Sub SF_Spreadsheet1_SelectionChange()
        set WorkSheet_SS = document.getElementById("SF_Spreadsheet1")
        Dim Row 
	    Dim Col
	    MaxCol = WorkSheet_SS.ActiveSheet.UsedRange.Columns.Count 
        MaxRow = WorkSheet_SS.ActiveSheet.UsedRange.Rows.Count 
        sumvalue = 0 
        sumcount = 0 
        colType = "Number"
        
        for Each Row In WorkSheet_SS.Selection.Rows 
		    if Row.row > MaxRow then 
		        exit for 
            end if 
            for Each Col In WorkSheet_SS.Selection.Columns 
	    	    if Col.column > MaxCol then 
	 	 	        exit for 
                end if 
                if VarType(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value)>=2 and VarType(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value)<=5 then 
	                if sumcount=0 and InStr(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).NumberFormat,"%")<>0 then
	                    colType = "Percent"
	                end if
	                if colType = "Percent" then 
	                    sumvalue = sumvalue + (WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value * 100)
	                else
	                    sumvalue = sumvalue + WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value 
	                end if
	                sumcount = sumcount + 1
                end if 
            next 
        next 

        if sumcount<>0 Then
            if colType = "Percent" then
                avg = Round(sumvalue / sumcount,2)
            else
                avg = Round(sumvalue / sumcount,0)
            end if
        else
            avg = 0
        end if
        if colType = "Percent" then
            window.status = "Average: " & FormatNumber(avg,2) & "%" & "  Count: " & FormatNumber(sumcount,0) & "  Sum: " & FormatNumber(sumvalue,2) & "%"
        else
            window.status = "Average: " & FormatNumber(avg,0) & "  Count: " & FormatNumber(sumcount,0) & "  Sum: " & FormatNumber(sumvalue,0)
        end if
        
    End Sub 
    </script>

</asp:PlaceHolder>

<script type="text/javascript">
    if ($get('SF_Spreadsheet1') != undefined && '<%= Me.SFModel.SF_Lock %>' == 'True') {
        $get('SF_Spreadsheet1').activeSheet.cells.locked = true;
        $get('SF_Spreadsheet1').activeSheet.protection.enabled = true;
    }
</script>

<%--    </ContentTemplate>
</asp:UpdatePanel>--%>